<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m210110_152711_CREATE_DB_ONE
 */
class m210110_152711_CREATE_DB_ONE extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 销售合同信息
        $this->createTable('ai_agreement', [

            "id" =>             Schema::TYPE_PK,
            "code" =>           Schema::TYPE_STRING. "(255) NOT NULL COMMENT '合同编号'",
            "customer_id" =>    Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '客户ID'",
            "type" =>     Schema::TYPE_INTEGER. "(1) DEFAULT  '1' COMMENT '1 内贸 2外贸 '",
            "order_type" =>     Schema::TYPE_INTEGER. "(1) DEFAULT  '1' COMMENT '1 首签 2维修 '",
            "sale_currency" =>   Schema::TYPE_STRING. "(10) NULL COMMENT '合同币种'",
            "sale_price" =>      Schema::TYPE_DECIMAL."(10,2) DEFAULT '0.00' COMMENT '合同金额' ",

            "payment_type" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '付款方式'",
            "payment_date" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '货期'",
            "warranty" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '质保期'",
            "exemption" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '免表'",

            "trade_company" =>   Schema::TYPE_STRING. "(128)  NULL COMMENT '外贸公司'",
            "trade_contract" =>   Schema::TYPE_STRING. "(128) NULL COMMENT '外贸合同号'",
            "invoice_no" =>   Schema::TYPE_STRING. "(128)  NULL COMMENT '开票号'",
            "trade_main" =>   Schema::TYPE_STRING. "(128) NULL COMMENT '签约主体'",
            "send_date" =>      Schema::TYPE_DATE. " NULL COMMENT '发货日期' ",
            "install_date" =>      Schema::TYPE_DATE. " NULL COMMENT '安装日期' ",
            "remarks" =>   Schema::TYPE_STRING. "(522)  NULL COMMENT '备注'",
            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1提交 2删除'",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间' ",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",

        ], $tableOptions);

         // 客户信息
        $this->createTable('ai_goods', [

            "id" =>             Schema::TYPE_PK,
            "agreement_id" =>    Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '合同ID'",
            "name" =>           Schema::TYPE_STRING. "(255) NOT NULL COMMENT '货品名称'",

        ], $tableOptions);


    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m210110_152711_CREATE_DB_ONE cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m210110_152711_CREATE_DB_ONE cannot be reverted.\n";

        return false;
    }
    */
}
